package javabase.schoolwork.day5_30;

/**
 * @author fance
 * @date 2018/5/30 17:43
 */
public class VipAccount extends Account implements InterestRate{
    @Override
    public boolean deposit(double money) {
        this.balance += money;
        return true;
    }

    @Override
    public boolean withdaw(double money) {
        if (money > this.balance) {
            System.out.println("余额不足");
            return false;
        }
        this.balance -= money;
        return true;
    }


    /**
     * 普通用户利率为vip的二分之一
     * 计算利息
     * @param prin
     * @param rate
     * @param n
     * @return
     */
    @Override
    public double calcRate(double prin, double rate, int n) {
        if (n <= 0) {
            return 0;
        }
        if (n < 3) {
            rate += 0.2;
        } else if (n < 5) {
            rate += 0.6;
        } else {
            rate += 1;
        }
        return prin * rate * n;
    }
}
